package lamnhungoc.controller;

import lamnhungoc.pojo.KhachHang;
import lamnhungoc.service.KhachHangService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class DangNhapController {
	@Autowired
	private KhachHangService khachHangService;

	@RequestMapping(value = "/Trang-Dang-Nhap", method = RequestMethod.GET)
	public ModelAndView hienThiTrangDangKy() {
		ModelAndView mav = new ModelAndView("Trang-Dang-Nhap");
		KhachHang kh = new KhachHang();
		mav.getModelMap().put("Trang-Dang-Nhap", kh);
		return mav;
	}

	@RequestMapping(value = "/Trang-Dang-Nhap", method = RequestMethod.POST)
	public String create(
			@ModelAttribute("Trang-Dang-Nhap") KhachHang khachhang,
			BindingResult result, SessionStatus status) {
		String userName = khachhang.getTenDangNhap();
		String passWord = khachhang.getMatKhau();
		if(khachHangService.isKhacHang(userName, passWord)){
			return "Trang-Nhat";
		}
		return "Trang-Dang-Nhap";

	}

}
